#! gmake

#
# Copyright (C) 2006 Laurent Bessard
# 
# This file is part of canfestival, a library implementing the canopen
# stack
# 
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# 
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
# 
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
# 

PREFIX = SUB_PREFIX
INSTDIR = $(DESTDIR)$(PREFIX)

# Install the real Python binaries only if we have Python 2. Otherwise,
# install shell scripts which just print a warning and exit with an error
# return value
ifeq ($(python_major_version), 2)
    # install the real Python binaries only if we have Python 2
	OBJDICTEDIT = 'objdictedit.py'
	OBJDICTGEN = 'objdictgen.py'
else
	# install warning scripts if we don't have Python 2
	OBJDICTEDIT = 'objdictedit_warn.sh'
	OBJDICTGEN = 'objdictgen_warn.sh'
endif

all: gnosis

gnosis: gnosis/version.py

gnosis/version.py:
	#wget http://gnosis.cx/download/Gnosis_Utils-current.tar.gz
	mkdir -p gnosis_extract
	tar xzof Gnosis_Utils-current.tar.gz -C gnosis_extract
	mv gnosis_extract/Gnosis_Utils-*/gnosis .
	rm -rf gnosis_extract

install: gnosis
	# Add an objdictgen directory in the install location and copy needed
	# files from this directory to there
	mkdir -p $(INSTDIR)/canfestival
	cp -r *.py* objdict*.sh config doc doc_index locale examples gnosis *.ico $(INSTDIR)/canfestival
	chmod -R a+r $(INSTDIR)/canfestival
	# Add objdictedit and objdictgen shortcuts in the install bin directory
	mkdir -p $(INSTDIR)/bin
	ln -sf $(INSTDIR)/canfestival/$(OBJDICTEDIT) $(INSTDIR)/bin/objdictedit
	chmod +x $(INSTDIR)/canfestival/$(OBJDICTEDIT)
	ln -sf $(INSTDIR)/canfestival/$(OBJDICTGEN) $(INSTDIR)/bin/objdictgen
	chmod +x $(INSTDIR)/canfestival/$(OBJDICTGEN)

uninstall:
	rm -rf $(INSTDIR)/canfestival
	rm -f $(INSTDIR)/bin/objdictedit
	rm -f $(INSTDIR)/bin/objdictgen

clean:

mrproper: clean
	rm -f Gnosis_Utils-current.tar.gz
	rm -rf gnosis


